PCA Index Interactive Visualization Examples

PCA Index Interactive Visualization Examples#

import plotly.express as px

import config
import load_fred
import pca_index

DATA_DIR = config.DATA_DIR
df = load_fred.load_fred(data_dir=DATA_DIR)
dfn = pca_index.transform_series(df)
/home/runner/work/example-updating-Diana/example-updating-Diana/src/pca_index.py:31: FutureWarning:

The default fill_method='pad' in Series.pct_change is deprecated and will be removed in a future version. Either fill in any non-leading NA values prior to calling pct_change or specify 'fill_method=None' to not fill NA values.

/home/runner/work/example-updating-Diana/example-updating-Diana/src/pca_index.py:32: FutureWarning:

The default fill_method='pad' in Series.pct_change is deprecated and will be removed in a future version. Either fill in any non-leading NA values prior to calling pct_change or specify 'fill_method=None' to not fill NA values.
## Visualize Principal Component 1
pc1, loadings = pca_index.pca(dfn, module="scikitlearn")
pc1.plot();
../../_images/5170a3d0864b1542593bc84962d7c801f3943917ba4be84429be0d4778aea661.png
# Simple version
fig = px.line(pc1)
fig.show()
# Using slider and quick views
pca_index.pc1_line_plot(pc1)
## Visualize normalized and raw series
dfn.plot(subplots=True, figsize=(10, 10));
../../_images/2b4afbf6b339da7f4fcf305ddadd6d0792008bf9cfe31b26fc165d6f77aa6b04.png
fig = px.line(dfn, facet_col="variable", facet_col_wrap=1)
fig.update_yaxes(matches=None)
fig.show()
pca_index.plot_unnormalized_series(df)
pca_index.plot_normalized_series(dfn)